package com.bdy.lm.taximanager.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by LM on 2017/3/20 0020.
 *  旧版本 暂时不用
 */

public class TransitionInfo {

    private Map<String, Object> transInfo = new HashMap<String, Object>();//交易信息
    private String up;//上车时间
    private String down;//下车时间
    private double sum;//金额
    private double price;//单价
    private double distance;//总里程
    private String spentTime;//用时
    private int hour;
    private int minute;
    private double nRun;//空驶里程
    private String journey;//运行状态（单程或往返）
    private String evaluate="";//评价
    public static TransitionInfo transitionInfo = null;

    public static TransitionInfo newInstance(List data) {
        if (transitionInfo == null) {
            transitionInfo = new TransitionInfo(data);
        }
        return transitionInfo;
    }

    public TransitionInfo(List data) {
        up = "20" + turn((byte) data.get(3)) + "-" + turn((byte) data.get(4)) + "-" + turn((byte) data.get(5)) + " " + turn((byte) data.get(6)) + ":" + turn((byte) data.get(7));
        transInfo.put("getOnTime", up);
        down = "20" + turn((byte) data.get(8)) + "-" + turn((byte) data.get(9)) + "-" + turn((byte) data.get(10)) + " " + turn((byte) data.get(11)) + ":" + turn((byte) data.get(12));
        transInfo.put("getOffTime", down);
        sum = (((byte) data.get(13) & 0xf0) >> 4) * 100 + ((byte) data.get(13) & 0x0f) * 10 + (((byte) data.get(14) & 0xf0) >> 4) + ((byte) data.get(14) & 0x0f) * 0.1;
        price = (((byte) data.get(15) & 0xf0) >> 4) * 10 + ((byte) data.get(15) & 0x0f) + (((byte) data.get(16) & 0xf0) >> 4) * 0.1 + ((byte) data.get(16) & 0x0f) * 0.01;
        distance = (((byte) data.get(17) & 0xf0) >> 4) * 100 + ((byte) data.get(17) & 0x0f) * 10 + (((byte) data.get(18) & 0xf0) >> 4) + ((byte) data.get(18) & 0x0f) * 0.1;
        hour = (((byte) data.get(19) & 0xf0) >> 4) * 10 + ((byte) data.get(19) & 0x0f);
        minute = (((byte) data.get(20) & 0xf0) >> 4) * 10 + ((byte) data.get(20) & 0x0f);
        int second = (((byte) data.get(21) & 0xf0) >> 4) * 10 + ((byte) data.get(21) & 0x0f);
        nRun = (((byte) data.get(22) & 0xf0) >> 4) * 100 + ((byte) data.get(22) & 0x0f) * 10 + (((byte) data.get(23) & 0xf0) >> 4) + ((byte) data.get(23) & 0x0f) * 0.1;
        spentTime = hour + "h" + minute + "m" + second + "s";

        transInfo.put("spendTime", spentTime);
        if (getBooleanArray((byte) data.get(24))[7] == 0) {
            journey = "double";
        } else if (getBooleanArray((byte) data.get(22))[7] == 1) {
            journey = "single";
        }
        transInfo.put("journey", journey);
        if (getBooleanArray((byte) data.get(24))[6] == 0) {
            transInfo.put("money", sum + "p");
            transInfo.put("price", price + "p");
        } else if (getBooleanArray((byte) data.get(22))[6] == 1) {
            transInfo.put("money", sum + "y");
            transInfo.put("price", price + "y");
        }
        if (getBooleanArray((byte) data.get(24))[6] == 0) {
            transInfo.put("distance", distance + "m");
            transInfo.put("nullRun", nRun + "m");
        } else if (getBooleanArray((byte) data.get(24))[6] == 1) {
            transInfo.put("distance", distance + "k");
            transInfo.put("nullRun", nRun + "k");
        }
    }

    private String turn(byte da) {
        int high = (da & 0xf0) >> 4;
        int low = da & 0x0f;
        return String.valueOf(high * 10 + low);
    }

    public byte[] getBooleanArray(byte b) {//获取比特数据位的值
        byte[] array = new byte[8];
        for (int i = 7; i >= 0; i--) {
            array[i] = (byte) (b & 1);
            b = (byte) (b >> 1);
        }
        return array;
    }

    public Map<String, Object> getTransInfo() {
        return transInfo;
    }

    public String getUp() {
        return up;
    }

    public String getDown() {
        return down;
    }

    public double getSum() {
        return sum;
    }

    public double getPrice() {
        return price;
    }

    public double getDistance() {
        return distance;
    }

    public String getSpentTime() {
        return spentTime;
    }

    public double getnRun() {
        return nRun;
    }

    public String getJourney() {
        return journey;
    }

    public String getEvaluate() {
        return evaluate;
    }

    public void setEvaluate(String evaluate) {
        this.evaluate = evaluate;
        transInfo.put("evaluate", evaluate);
    }

    public int getHour() {
        return hour;
    }

    public int getMinute() {
        return minute;
    }
}
